from django.contrib import admin

from z_web.models import *


# Register your models here.

# admin定制
class MovieAdmin(admin.ModelAdmin):
    list_display = ["name", "up_time"]  # 列表显示字段
    filter_horizontal = ('label',)  # 外键选择

    date_hierarchy = "up_time"  # 时间筛选
    list_filter = ["label", ]  # 过滤器

    ordering = ("-pk", )

class DetailInline(admin.TabularInline):
    model = VisitDetail
    can_delete = False
    show_change_link = False
    extra = 0
    readonly_fields = ["visit_ip",  "visit_page", "visit_times", "visit_source", "visit_date", ]
    # fields = ["visit_ip", "visit_times",  "visit_page", "visit_source"]


class VisitRecordAdmin(admin.ModelAdmin):
    search_fields = ["visit_token"]
    list_display = ["visit_token", "visit_times", "update_time"]  # 列表显示字段
    # filter_horizontal = ('detail',)  # 外键选择
    # list_filter = ("visit_source", "visit_page")
    inlines = [DetailInline, ]
    date_hierarchy = "update_time"  # 时间筛选
    ordering = ("-pk", )


admin.site.register(MovieLabel)  # 注册
admin.site.register(MovieNew)  
admin.site.register(FriendlyLink)  
admin.site.register(Movie, MovieAdmin)
admin.site.register(VisitRecord, VisitRecordAdmin)
